/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yunhoo.checkFlow.bean;

import com.ibatis.dao.client.DaoManager;
import com.yunhoo.base.bean.DepartmentBean;
import com.yunhoo.base.db.dao.PersonDao;
import com.yunhoo.base.db.impl.RoleImpl;
import com.yunhoo.base.model.Department;
import com.yunhoo.base.model.Person;
import com.yunhoo.base.model.Role;
import com.yunhoo.checkFlow.db.dao.BaseDao;
import com.yunhoo.checkFlow.model.CheckInfo;
import com.yunhoo.checkFlow.model.CheckNode;
import com.yunhoo.checkFlow.model.CheckTree;
import com.yunhoo.checkFlow.model.FlowModel;
import com.yunhoo.checkFlow.model.Level;
import com.yunhoo.checkFlow.model.Node;
import com.yunhoo.checkFlow.util.QueryCondition;
//import com.yunhoo.pub.dao.BaseDao;
//import com.yunhoo.pub.db.impl.DepartmentImpl;
import com.yunhoo.sys.db.config.DaoConfig;
import com.yunhoo.sys.util.common.FacesUtils;
import com.yunhoo.sys.util.common.LoginParam;
import com.yunhoo.sys.util.common.NavigationTool;
import com.yunhoo.sys.util.common.Null;
import com.yunhoo.sys.util.common.ToolKit;
import com.yunhoo.sys.util.tree.MyTreeNodeImpl;
import com.yunhoo.sys.util.tree.TreeUtil;
import java.sql.SQLException;
//import com.yunhoo.system.util.err.ErrMessage;
//import com.yunhoo.system.util.pub.QueryCondition;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import javax.faces.component.UIData;
import javax.faces.context.FacesContext;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;
import org.richfaces.component.UIExtendedDataTable;
import org.richfaces.event.TreeSelectionChangeEvent;


import org.richfaces.model.TreeNode;
import org.richfaces.model.TreeNodeImpl;

/**
 *
 * @author Administrator
 */
@ManagedBean(name = "checkFlowBean")
@SessionScoped
public class CheckFlowBean {

    private static BaseDao type;
    private static PersonDao perDao;
    private FlowModel flowmodel;//流程模型
    private List<CheckTree> items = new ArrayList<CheckTree>();
    private List<CheckTree> freeItems = new ArrayList<CheckTree>();
    private TreeNode rootNode = null;
    private TreeNode allNode = null;
    private int counter = 1;
    private int tree = 1;
    private List<FlowModel> alllist;
    private DataModel<FlowModel> allModel = new ListDataModel<FlowModel>();
    private DataModel model = new ListDataModel();
    private List<Level> checknodes;//审批节点
    private UIData data = null;
    //private Selection selection = new SimpleSelection();
    private List<SelectItem> types;
    private List<SelectItem> nodes;
    private String testurl = "/checkflow/wstep1.xhtml";
    private String deleteId;
    private String test;
    private List<Level> levellist;
    //private SimpleSelection levelselection = new SimpleSelection();
    private Level currentItem = new Level();
    //private SimpleSelection nodeselection = new SimpleSelection();
    private String deleteNode;
    private List<CheckTree> currennodes;
    private Collection selection;
    private Collection levelselection;
    private Collection<Level> nodeselection;
    private int levelIndex = -1;
    private int m = -1;
    private DataModel<Level> levelModel = new ListDataModel<Level>();
    private int t = -1;
    private TreeNode deptNode = null;//部门树
    private List<Person> personli = null;//人员列表
    private int personIndex = -1;
    private List<Role> roleList = null;//角色列表

    /**
     * Creates a new instance of CheckFlowBean
     */
    public CheckFlowBean() {
        flowmodel = new FlowModel();
        flowmodel.setOrgCode(LoginParam.getOrg().getCode());
        
        DaoManager daoManager = DaoConfig.getDaoManager();
        type = (BaseDao) daoManager.getDao(BaseDao.class);
        perDao = (PersonDao) daoManager.getDao(PersonDao.class);
        //loadTree();
        loadModelTree();
    }

    //加载树
    private void loadTree() {
        rootNode = new TreeNodeImpl();
        List checkflows = (ArrayList) type.getFirstLevel("flowmodel");
        addNodes(checkflows, rootNode);
    }

    //加载流程模型
    private void loadModelTree() {
        allNode = new TreeNodeImpl();
        List temp = type.getAllList("flowmodel");
        addAllNodes(temp, allNode);
    }

    public TreeNode getDeptNode() {
        if (deptNode == null) {
            DepartmentBean departmentBean = (DepartmentBean) FacesUtils.getManagedBean("departmentBean");
            deptNode = departmentBean.getRootNode();
        }
        return deptNode;
    }

    //节点
    public void addAllNodes(List inventtypes, TreeNode node) {
        for (int i = 0; i < inventtypes.size(); i++) {
            String str = (String) inventtypes.get(i);
            FlowModel flowModel = new FlowModel();
            flowModel.setFname(str);
            flowModel.setTreetype("0");
            flowModel.setYear(str);
            MyTreeNodeImpl nodeImpl = new MyTreeNodeImpl(false, flowModel);
            node.addChild(new Integer(tree), nodeImpl);
            tree++;

            FlowModel wfm = new FlowModel();
            wfm.setFname("未发布");
            wfm.setTreetype("10");
            wfm.setType(str);
            wfm.setYear(str);
            MyTreeNodeImpl wfabu = new MyTreeNodeImpl(false, wfm);
            nodeImpl.addChild(new Integer(tree), wfabu);
            tree++;
            //增加未发布流程
            Map para = new HashMap();
            para.put("orgCode",LoginParam.getOrg().getCode());
            para.put("createtime", str);
            para.put("isPub", "0");
            List temp1 = type.getGenSecList(para, "flowmodel");
            if (temp1 != null && temp1.size() > 0) {
                for (int j = 0; j < temp1.size(); j++) {
                    FlowModel md1 = (FlowModel) temp1.get(j);
                    md1.setTreetype("2");
                    md1.setYear(str);
                    MyTreeNodeImpl ni1 = new MyTreeNodeImpl(true, md1);
                    wfabu.addChild(new Integer(tree), ni1);
                    tree++;
                }
            }
            FlowModel fm = new FlowModel();
            fm.setFname("已发布");
            fm.setType(str);
            fm.setTreetype("11");
            fm.setYear(str);
            MyTreeNodeImpl fabu = new MyTreeNodeImpl(false, fm);
            nodeImpl.addChild(new Integer(tree), fabu);
            tree++;
            //增加发布流程
            para.put("isPub", "1");
            List temp2 = type.getGenSecList(para, "flowmodel");
            if (temp2 != null && temp2.size() > 0) {
                for (int j = 0; j < temp2.size(); j++) {
                    FlowModel md2 = (FlowModel) temp2.get(j);
                    md2.setTreetype("2");
                    md2.setYear(str);
                    MyTreeNodeImpl ni2 = new MyTreeNodeImpl(true, md2);
                    fabu.addChild(new Integer(tree), ni2);
                    tree++;
                }
            }
            //已终止 
            FlowModel yzz = new FlowModel();
            yzz.setFname("已终止");
            yzz.setType(str);
            yzz.setTreetype("12");
            yzz.setYear(str);
            MyTreeNodeImpl zz = new MyTreeNodeImpl(false, yzz);
            nodeImpl.addChild(new Integer(tree), zz);
            tree++;
            //增加已终止流程
            para.put("isPub", "2");
            List temp3 = type.getGenSecList(para, "flowmodel");
            System.out.println(" temp3 :" + temp3.size());
            if (temp3 != null && temp3.size() > 0) {
                for (int j = 0; j < temp3.size(); j++) {
                    FlowModel md3 = (FlowModel) temp3.get(j);
                    md3.setTreetype("2");
                    md3.setYear(str);
                    MyTreeNodeImpl ni3 = new MyTreeNodeImpl(true, md3);
                    zz.addChild(new Integer(tree), ni3);
                    tree++;
                }
            }
        }
    }

    //检查模型名称是否重复
    public void checkUse() {
        List temp = type.isExist(flowmodel, "flowmodel");
        QueryCondition dqcb = (QueryCondition) FacesUtils.getManagedBean("queryBean");
        if (temp == null || temp.size() < 1) {
            //ToolKit.msgs_err("");//dqcb.setErr(new ErrMessage("该名称可用"));
            ToolKit.msgs_info("该名称可用");
        } else {
            //ToolKit.msgs_err("");//dqcb.setErr(new ErrMessage("该名称已存在"));
            ToolKit.msgs_err("该名称已存在");
            flowmodel.setFname("");
        }
    }

    //保存 2010-9-25
    public void save() {
        QueryCondition dqcb = (QueryCondition) FacesUtils.getManagedBean("queryCondition");
        if (levellist != null && levellist.size() > 0) {
            List checkFlowNameRepeatli = type.getGenListByObject(flowmodel, "flowmodel");
            if (checkFlowNameRepeatli != null && !checkFlowNameRepeatli.isEmpty()) {
                ToolKit.msgs_err("模型名称重复");
                return;
            }
            CheckInfo info = new CheckInfo();
            for (int i = 0; i < levellist.size(); i++) {
                Level str = levellist.get(i);
                List<CheckTree> temp = str.getNodes();
                if (temp != null && temp.size() > 0) {
                    flowmodel.setCreatetime(new Date());
                    flowmodel.setIsPub("0");
                    info.setFlowmodel(flowmodel);
                    CheckNode check = new CheckNode();
                    check.setCheckLevel(str.getLevel());
                    for (int k = 0; k < temp.size(); k++) {
                        check.getChecker().setCpsn_number(temp.get(k).getId());
                        check.getChecker().setCpsn_name(temp.get(k).getName());
                        check.setRoleId(temp.get(k).getRoleId());
                        check.setRole(temp.get(k).getRole());
                        info.setChecknode(check);
                        type.insert(info, "flowmodel");
                    }
                } else {
                    //ToolKit.msgs_err("");//dqcb.setErr(new ErrMessage(str.getLevel() + "级，没有选择审批人"));
                    ToolKit.msgs_err(str.getLevel() + "级，没有选择审批人");
                }
            }
            currentItem = new Level();
            alllist = new ArrayList<FlowModel>();
            alllist.add(info.getFlowmodel());
            flowmodel = new FlowModel();
            checknodes = levellist;
            loadModelTree();
            levellist = new ArrayList<Level>();
            testurl = "/checkflow/wstep1.xhtml";
        } else {
            //ToolKit.msgs_err("");//dqcb.setErr(new ErrMessage("保存失败，没有选择审批人"));
            ToolKit.msgs_err("保存失败，没有选择审批人");
        }
    }

    private void addNodes(List<CheckTree> depts, TreeNode node) {
        for (int i = 0; i < depts.size(); i++) {
            CheckTree det = (CheckTree) depts.get(i);
            String isEnd = det.getIsEnd().trim();
            String key = det.getId();
            boolean hasNoChild = false;
            if (det.getType().equals("0")) {
                List<CheckTree> subPer = type.getListByQuery(det, "flowmodel");
                hasNoChild = check(subPer);
            } else {
                hasNoChild = true;
            }
            boolean isleaf = "1".equals(isEnd); //true : 是叶子节点
            boolean leaf = isleaf && hasNoChild;
            MyTreeNodeImpl nodeImpl = new MyTreeNodeImpl(leaf, det);
            node.addChild(key, nodeImpl);
            det.setGradeLevel(det.getGradeLevel() + 1);
            if (isEnd.equals("0") && det.getType().equals("0")) {
                List<CheckTree> subDepts = type.getSubLevel(det, "flowmodel");
                addNodes(subDepts, nodeImpl);
            } else if (isEnd.equals("1")) {
                List<CheckTree> subDepts = type.getListByQuery(det, "flowmodel");
                addNodes(subDepts, nodeImpl);
            }
        }
    }

    public boolean check(List li) {
        if (li == null || li.isEmpty()) {
            return true;
        } else {
            return false;
        }
    }

    //添加节点
    private void addNodes_(List inventtypes, TreeNode node) {
        for (int i = 0; i < inventtypes.size(); i++) {
            CheckTree det = (CheckTree) inventtypes.get(i);
            String isEnd = det.getIsEnd();
            String key = det.getId();
            boolean isleaf = "1".equals(isEnd); //true : 是叶子节点
            MyTreeNodeImpl nodeImpl = new MyTreeNodeImpl(isleaf, det);
            node.addChild(key, nodeImpl);
            det.setGradeLevel(det.getGradeLevel() + 1);
            if (isEnd.equals("0") && det.getType().equals("0")) {
                List subDepts = type.getSubLevel(det, "flowmodel");
                addNodes(subDepts, nodeImpl);
            } else if (isEnd.equals("1")) {
                List subDepts = type.getListByQuery(det, "flowmodel");
                addNodes(subDepts, nodeImpl);
            }
        }
    }

    //选择审批人
    public void processSelection(TreeSelectionChangeEvent event) {
        CheckTree obj = (CheckTree) TreeUtil.listener(event);
        if (items == null) {
            items = new ArrayList<CheckTree>();
        }
        if (obj.getType().equals("1")) {
            currentItem.getNodes().add(obj);
        }
    }

    public void roleSelected(String roleId, String role) {
        System.out.println(" * * * " + "roleId : " + roleId + " -- " + role + "  * * * ");
        personli = perDao.queryListByRoleId(roleId);
        levellist.get(m).setRoleId(roleId);
        levellist.get(m).setRole(role);
    }

    public void treeSelected(TreeSelectionChangeEvent event) {
        System.out.println(" * * * " + "dept tree selected" + "  * * * ");
        Department dept = (Department) TreeUtil.listener(event);
        if (1 == dept.getIsEnd()) {
            try {
                //personli = PersonImpl.getPersonInfo(dept.getCode());
                Person param = new Person();
                param.setOrgCode(LoginParam.getOrg().getCode());
                param.setIyear(LoginParam.getIyear());
                param.setDeptCode(dept.getCode());
                personli = perDao.queryListByDept(param);
            } catch (SQLException ex) {
                Logger.getLogger(CheckFlowBean.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
        } else personli = null;
    }

    public void personSelected() {
        if (!Null.check(personli) && m != -1) {
            for (Person per : personli) {
                if (per.isSelected()) {
                    CheckTree ct = new CheckTree();
                    ct.setId(per.getCpsn_number());
                    ct.setName(per.getCpsn_name());
                    ct.setRoleId(levellist.get(m).getRoleId());
                    ct.setRole(levellist.get(m).getRole());
                    currentItem.getNodes().add(ct);
                }
            }
        }
    }

    public List<FlowModel> getAlllist() {
        if (alllist == null) {
            alllist = new ArrayList<FlowModel>();
        }
        return alllist;
    }

    //退出审批流
    public void reback() {
        NavigationTool.getSelectedUrl("/welcome.xhtml");
    }

    public FlowModel getFlowmodel() {
        if (flowmodel == null) {
            flowmodel = new FlowModel();
        }
        return flowmodel;
    }

    public TreeNode getAllNode() {
        if (this.allNode == null) {
            loadModelTree();
        }
        return allNode;
    }

    public TreeNode getRootNode() {
        if (this.rootNode == null) {
            loadTree();
        }
        return rootNode;
    }

    public void setRootNode(TreeNode rootNode) {
        this.rootNode = rootNode;
    }

    public void takeSelection(AjaxBehaviorEvent event) {
        UIExtendedDataTable dataTable = (UIExtendedDataTable) event.getComponent();
        for (Object selectionKey : selection) {
            dataTable.setRowKey(selectionKey);
            flowmodel = (FlowModel) dataTable.getRowData();
            t = (int) dataTable.getRowIndex();
        }
        checknodes = type.getGenListByObject(flowmodel, "flowmodel");
    }

    public void tableRowSelected() {
        System.out.println("selected !!!");
        flowmodel = allModel.getRowData();
        System.out.println("flowmodel : " + flowmodel);
        checknodes = type.getGenListByObject(flowmodel, "flowmodel");
    }

    public void forCheck() {
        checknodes = type.getGenListByObject(flowmodel, "flowmodel");
        System.out.println("forcheck+++ : " + checknodes);
    }

    public void takeSelection_model(AjaxBehaviorEvent event) {
        UIExtendedDataTable dataTable = (UIExtendedDataTable) event.getComponent();
        for (Object selectionKey : levelselection) {
            dataTable.setRowKey(selectionKey);
            currentItem = (Level) dataTable.getRowData();
        }
    }

    public void levelliSelected(Integer rowKey) {
        System.out.println(" * * * " + "levelliselected rowKey : " + rowKey + "  * * * ");
        m = rowKey;
        currentItem = levellist.get(rowKey);
    }

    public void test() {
        for (Level temp : levellist) {
            System.out.println(" * * * " + "roleId : " + temp.getRoleId() + "  * * * ");
        }
    }

    //选中某一模块
    public void choiceModel() {
        List<Node> temp = type.getGenForthList(flowmodel, "flowmodel");
        if (temp != null && temp.size() > 0) {
            nodes = new ArrayList<SelectItem>();
            for (Node nod : temp) {
                nodes.add(new SelectItem(nod.getId(), nod.getName()));
            }
        } else {
            nodes = new ArrayList<SelectItem>();
        }
    }

    //选择流程模型树
    public void finish() {
        Date dd = new Date();
        QueryCondition dqcb = new QueryCondition();
        String fname = (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("modelname");
        System.out.println("__++: " + fname);
        String[] arr = fname.split(":");
        System.out.println("arr: " + Arrays.deepToString(arr));
        if (arr != null && arr.length > 1) {
            if (arr[1].equals("0")) {
                dd.setYear(Integer.parseInt(arr[0]) - 1900);
                dqcb.setFirstdate(dd);
                alllist = type.getGenList(dqcb, "flowmodel");
            } else if (arr[1].equals("10")) {
                dd.setYear(Integer.parseInt(arr[2]) - 1900);
                dqcb.setFirstdate(dd);
                dqcb.setCheck("0");
                alllist = type.getGenList(dqcb, "flowmodel");
            } else if (arr[1].equals("11")) {
                dd.setYear(Integer.parseInt(arr[2]) - 1900);
                dqcb.setFirstdate(dd);
                dqcb.setCheck("1");
                alllist = type.getGenList(dqcb, "flowmodel");
            } else if (arr[1].equals("2")) {
                System.out.println("实例:" + arr[3] + "|" + Integer.parseInt(arr[3]));
                dd.setYear(Integer.parseInt(arr[3]) - 1900);
                dqcb.setFirstdate(dd);
                dqcb.setForword(arr[0]);
                alllist = type.getGenList(dqcb, "flowmodel");
            } else if (arr[1].equals("12")) {
                dd.setYear(Integer.parseInt(arr[2]) - 1900);
                dqcb.setFirstdate(dd);
                dqcb.setCheck("2");
                alllist = type.getGenList(dqcb, "flowmodel");
            }
            allModel.setWrappedData(alllist);
        }
    }

    public void delete() {
        QueryCondition dqcb = (QueryCondition) FacesUtils.getManagedBean("queryCondition");
        type.delete(flowmodel, "flowmodel");
        alllist.remove(t);
        loadModelTree();
        ToolKit.msgs_err("删除成功");//dqcb.setErr(new ErrMessage("删除成功"));
    }

    //终止选中项
    public void resultModel() {
        QueryCondition dqcb = (QueryCondition) FacesUtils.getManagedBean("queryCondition");
        if (!flowmodel.getIsPub().equals("2")) {
            flowmodel.setIsPub("2");
        }
        type.update(flowmodel, "flowmodel");
        ToolKit.msgs_err("终止成功");//dqcb.setErr(new ErrMessage("终止成功"));
        loadModelTree();
    }

    //恢复选中项
    public void rebackModel() {
        System.out.println("恢复选中项------------");
        QueryCondition dqcb = (QueryCondition) FacesUtils.getManagedBean("queryCondition");

        if (flowmodel.getIsPub().equals("2")) {
            flowmodel.setIsPub("0");
            type.update(flowmodel, "flowmodel");
            loadModelTree();
            ToolKit.msgs_err("恢复成功");//ToolKit.msgs_err("");//dqcb.setErr(new ErrMessage("恢复成功"));
        }
    }

    //发布流程
    public void publishModel() {
        System.out.println("publishModel !!!");
        QueryCondition dqcb = (QueryCondition) FacesUtils.getManagedBean("queryCondition");
        if (flowmodel.getIsPub().equals("0")) {
            //检查是否有已发布节点
            List temp = type.getGenSecListByObject(flowmodel, "flowmodel");
            if (temp == null || temp.size() < 1) {
                flowmodel.setIsPub("1");
                type.update(flowmodel, "flowmodel");
                loadModelTree();
                ToolKit.msgs_info("发布成功");//dqcb.setErr(new ErrMessage("发布成功"));
            } else {
                ToolKit.msgs_err("此节点有已发布流程模型");//dqcb.setErr(new ErrMessage("此节点有已发布流程模型"));
            }
        } else if (flowmodel.getIsPub().equals("1")) {
            flowmodel.setIsPub("0");
            type.update(flowmodel, "flowmodel");
            loadModelTree();
            ToolKit.msgs_info("取消发布成功");//dqcb.setErr(new ErrMessage("取消发布成功"));
        } else {
            ToolKit.msgs_err("操作失败");//dqcb.setErr(new ErrMessage("操作失败"));
        }
    }

    public void publishModel2(AjaxBehaviorEvent event) {
        QueryCondition dqcb = (QueryCondition) FacesUtils.getManagedBean("queryCondition");
        UIExtendedDataTable dataTable = (UIExtendedDataTable) event.getComponent();
        for (Object selectionKey : selection) {
            dataTable.setRowKey(selectionKey);
            flowmodel = (FlowModel) dataTable.getRowData();
            if (flowmodel.getIsPub().equals("0")) {
                //检查是否有已发布节点
                List temp = type.getGenSecListByObject(flowmodel, "flowmodel");
                if (temp == null || temp.size() < 1) {
                    flowmodel.setIsPub("1");
                    type.update(flowmodel, "flowmodel");
                    loadModelTree();
                    ToolKit.msgs_err("发布成功");//dqcb.setErr(new ErrMessage("发布成功"));
                } else {
                    ToolKit.msgs_err("此节点有已发布流程模型");//dqcb.setErr(new ErrMessage("此节点有已发布流程模型"));
                }
            } else if (flowmodel.getIsPub().equals("1")) {
                flowmodel.setIsPub("0");
                type.update(flowmodel, "flowmodel");
                loadModelTree();
                ToolKit.msgs_err("取消发布成功");//dqcb.setErr(new ErrMessage("取消发布成功"));
            } else {
                ToolKit.msgs_err("操作失败");//dqcb.setErr(new ErrMessage("操作失败"));
            }
        }
    }

    public void selectCurrennodes() {
        checknodes = type.getGenListByObject(flowmodel, "flowmodel");
        if (levelIndex != -1) {
            currennodes = checknodes.get(levelIndex - 1).getNodes();
        }
    }

    public List<Level> getChecknodes() {
        if (checknodes == null) {
            checknodes = new ArrayList<Level>();
        }
        return checknodes;
    }

    public void setChecknodes(List<Level> checknodes) {
        this.checknodes = checknodes;
    }

    public List<SelectItem> getNodes() {
        if (nodes == null) {
            nodes = new ArrayList<SelectItem>();
        }
        return nodes;
    }

    public List<SelectItem> getTypes() {
        if (types == null) {
            types = new ArrayList<SelectItem>();
            String orgCode = LoginParam.getOrg().getCode();
            List<Node> temp = type.getGenThirdList(orgCode, "flowmodel");
            if (temp != null && temp.size() > 0) {
                for (Node nod : temp) {
                    types.add(new SelectItem(nod.getId(), nod.getName()));
                }
            }
        }
        return types;
    }

    public List getLevellist() {
        if (levellist == null) {
            levellist = new ArrayList<Level>();
        }
        return levellist;
    }

    public void add() {
        if (levellist == null) {
            levellist = new ArrayList<Level>();
        }
        levellist.add(new Level(levellist.size()));
    }

    public void remove(Integer rowKey) {
        levellist.remove(rowKey.intValue());
        if (levellist != null && levellist.size() > 0) {
            for (int k = 0; k < levellist.size(); k++) {//为Level重设key
                levellist.get(k).setKey(k);
            }
        }
    }

    public void deleteNode() {
        if (personIndex != -1) {
            List<CheckTree> rnli = currentItem.getNodes();
            rnli.remove(personIndex);
        }
    }

    public List<CheckTree> getCurrennodes() {
        if (currennodes == null) {
            currennodes = new ArrayList<CheckTree>();
        }
        return currennodes;
    }

    public void newFlowModel() {
        testurl = "/page/checkflow/wstep1.xhtml";
    }

    public void goWstep2() {
        testurl = "/page/checkflow/wstep2.xhtml";
    }

    public static BaseDao getType() {
        return type;
    }

    public static void setType(BaseDao type) {
        CheckFlowBean.type = type;
    }

    public List<CheckTree> getItems() {
        return items;
    }

    public void setItems(List<CheckTree> items) {
        this.items = items;
    }

    public List<CheckTree> getFreeItems() {
        return freeItems;
    }

    public void setFreeItems(List<CheckTree> freeItems) {
        this.freeItems = freeItems;
    }

    public int getCounter() {
        return counter;
    }

    public void setCounter(int counter) {
        this.counter = counter;
    }

    public int getTree() {
        return tree;
    }

    public void setTree(int tree) {
        this.tree = tree;
    }

    public DataModel<FlowModel> getAllModel() {
        return allModel;
    }

    public void setAllModel(DataModel<FlowModel> allModel) {
        this.allModel = allModel;
    }

    public DataModel getModel() {
        return model;
    }

    public void setModel(DataModel model) {
        this.model = model;
    }

    public UIData getData() {
        return data;
    }

    public void setData(UIData data) {
        this.data = data;
    }

    public String getTesturl() {
        return testurl;
    }

    public void setTesturl(String testurl) {
        this.testurl = testurl;
    }

    public String getDeleteId() {
        return deleteId;
    }

    public void setDeleteId(String deleteId) {
        this.deleteId = deleteId;
    }

    public String getTest() {
        return test;
    }

    public void setTest(String test) {
        this.test = test;
    }

    public void setLevellist(List<Level> levellist) {
        this.levellist = levellist;
    }

    public Level getCurrentItem() {
        return currentItem;
    }

    public void setCurrentItem(Level currentItem) {
        this.currentItem = currentItem;
    }

    public String getDeleteNode() {
        return deleteNode;
    }

    public void setDeleteNode(String deleteNode) {
        this.deleteNode = deleteNode;
    }

    public Collection getSelection() {
        return selection;
    }

    public void setSelection(Collection selection) {
        this.selection = selection;
    }

    public Collection getLevelselection() {
        return levelselection;
    }

    public void setLevelselection(Collection levelselection) {
        this.levelselection = levelselection;
    }

    public Collection<Level> getNodeselection() {
        return nodeselection;
    }

    public void setNodeselection(Collection<Level> nodeselection) {
        this.nodeselection = nodeselection;
    }

    public int getLevelIndex() {
        return levelIndex;
    }

    public void setLevelIndex(int levelIndex) {
        this.levelIndex = levelIndex;
    }

    public int getM() {
        return m;
    }

    public void setM(int m) {
        this.m = m;
    }

    public DataModel<Level> getLevelModel() {
        return levelModel;
    }

    public void setLevelModel(DataModel<Level> levelModel) {
        this.levelModel = levelModel;
    }

    public int getT() {
        return t;
    }

    public void setT(int t) {
        this.t = t;
    }

    public List<Person> getPersonli() {
        return personli;
    }

    public void setPersonli(List<Person> personli) {
        this.personli = personli;
    }

    public int getPersonIndex() {
        return personIndex;
    }

    public void setPersonIndex(int personIndex) {
        this.personIndex = personIndex;
    }

    public void setCurrennodes(List<CheckTree> currennodes) {
        this.currennodes = currennodes;
    }

    public static PersonDao getPerDao() {
        return perDao;
    }

    public static void setPerDao(PersonDao perDao) {
        CheckFlowBean.perDao = perDao;
    }

    public List<Role> getRoleList() {
        if (roleList == null) {
            roleList = RoleImpl.allList();
        }
        return roleList;
    }

    public void setRoleList(List<Role> roleList) {
        this.roleList = roleList;
    }
}
